home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / wx_lib10.zoo / wx_name.c < prev    next >
C/C++ Source or Header  |  1992-08-02  |  1KB  |  41 lines

  1. #include <wx_lib.h>
  2. #include <alloc.h>
  3. #include <string.h>
  4.  
  5. /*
  6.  * This function sets the window's name line to the contents of the string that
  7.  * is passed to it.  The string is copied into an internally allocated buffer,
  8.  * which is free()'d if non-NULL, that way we won't see any horrible memory
  9.  * leakage.
  10.  *
  11.  * Arguments:    The Window structure and a pointer to a NULL-terminated string.
  12.  * Returns:        TRUE if the assignment was successful, FALSE if not.
  13.  */
  14. int        wx_name(ws,sp)
  15. Window    *ws;
  16. char    *sp;
  17. {
  18.     /*
  19.      * If the buffer's pointer is non-NULL, free that section of memory, so we
  20.      * can allocate another buffer of the proper size.
  21.      */
  22.     if (ws->name != NULL) {
  23.         free(ws->name);
  24.     }
  25.     /*
  26.      * If we're succesful at allocating a new buffer, copy the string into it,
  27.      * set the Window's name pointer to the string, and return a non-error
  28.      * condition.
  29.      */
  30.     if ((ws->name = malloc(strlen(sp) + 1)) != NULL) {
  31.         strcpy(ws->name,sp);
  32.         wind_set(ws->hand,WF_NAME,ws->name);
  33.         return TRUE;
  34.     } else {
  35.         /*
  36.          * The malloc() failed, and so we need to report the error.
  37.          */
  38.         return FALSE;
  39.     }
  40. }
  41.